package ie.lawlor.amvc.controller;

import ie.lawlor.amvc.IController;
import ie.lawlor.amvc.event.EventName;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import junit.framework.TestCase;

public class Test extends TestCase {
    Class[] classes = new Class[]{IController.class};
    IController proxyController; 
    
    public void testCreation(){
      proxyController  = (IController)Proxy.newProxyInstance(ClassLoader.getSystemClassLoader(), 
                classes, new MyInvocationHandler());
      EventName event = proxyController.getEvent("event");
      assertNotNull("Event should not be null", event);
      assertEquals("testresult", event.name);
    }

}

class MyInvocationHandler implements InvocationHandler{
    public MyInvocationHandler(){
        
    }

    public Object invoke(Object arg0, Method method, Object[] args) throws Throwable {
        if (method.getName().equals("getEvent")){
            return new EventName("testresult");
        }
        return null;

    }
    
    
}
